package org.jeecg.modules.smartSchoolFiancial.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.val;
import org.jeecg.modules.smartSchoolFiancial.entity.SmartSchoolFiancial;
import org.jeecg.modules.smartSchoolFiancial.mapper.SmartSchoolFiancialMapper;
import org.jeecg.modules.smartSchoolFiancial.service.ISmartSchoolFiancialService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.text.SimpleDateFormat;

/**
 * @Description: 财务预审批表
 * @Author: jeecg-boot
 * @Date:   2022-01-15
 * @Version: V1.0
 */
@Service
public class SmartSchoolFiancialServiceImpl extends ServiceImpl<SmartSchoolFiancialMapper, SmartSchoolFiancial> implements ISmartSchoolFiancialService {

    @Override
    public void saveOrUpdateInfo(JSONArray form_component_values, String originator_userid) {
        {
            {
                SmartSchoolFiancial diyCwysp = new SmartSchoolFiancial();
                for (int i = 0; i < form_component_values.size(); i++) {
                    JSONObject jsonObject = form_component_values.getJSONObject(i);
                    String name = jsonObject.getString("name");
                    String value = jsonObject.getString("value");
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                    switch (name){
                        case "老师姓名":
                            diyCwysp.setTeacherName(value);
                            break;
                        case "老师工号":
                            diyCwysp.setTeacherWorkNumber(value);
                            break;
                        case "报销类型":
                            diyCwysp.setFiancialType(value);
                            break;
                        case "上传材料":
                            String s = value.replaceAll("\"", "");
                            String s1 = s.replace("[", "").replace("]", "");
                            diyCwysp.setFiancialDataString(s1);
                            break;
                        case "报销金额":
                            diyCwysp.setFiancialStanbdyStanbdy(value);
                            break;
                    }
                }


                diyCwysp.setFiancialStanbdy(originator_userid);
                System.out.println(diyCwysp);

                //保存
                this.save(diyCwysp);
            }
        }
    }
}
